/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonInfrastructure.accountManagement.session;


import javax.ejb.LocalBean;
import commonInfrastructure.accountManagement.entity.EmployeeEntity;
import commonInfrastructure.accountManagement.entity.SalesmanEntity;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Wei Haoyang
 */
@Stateless
@LocalBean
public class SalesmanSessionBean {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @PersistenceContext
    private EntityManager em;
    
    public SalesmanEntity getSalesmanById(Long EmployeeId)
    {
        return em.find(SalesmanEntity.class, EmployeeId);
    }
    
    public void addSalesman(SalesmanEntity salesmanEntity) throws Exception
    {
        try{
        em.persist(salesmanEntity);
        }catch(Exception e){
            throw e;
        }
        
    }
    public void editSalesmanEntity(SalesmanEntity salesmanEntity)
    {
        em.merge(salesmanEntity);
    }
    

    public void removeSalesmanEntity(Long salesmanId)
    {
        SalesmanEntity salesmanEntity = em.find(SalesmanEntity.class, salesmanId);
        em.remove(salesmanEntity);
    }
    
    public List<EmployeeEntity> getAllSalesman(){
        Query query = em.createQuery("SELECT s1 FROM SalesmanEntity s1");
        return query.getResultList();
    }
    

}
